package kuzha.runtime.qb;

import kuzha.KuzhaEngine;
import kuzha.KuzhaEngineFactory;
import kuzha.KuzhaObject;
import kuzha.runtime.AbstractValue;
import kuzha.runtime.KzBuiltinFunction;
import kuzha.runtime.KzTraitsObject;
import kuzha.runtime.KzUserObject;

public abstract class QbControl extends AbstractValue {
	public static final KuzhaObject TRAITS = new KzTraitsObject("QbControl", KuzhaEngineFactory.getRootObject());
	
	@Override
	public KuzhaObject getTraits() {
		return TRAITS;
	}
	
	@Override
	public Object toJavaObject() {
		return this;
	}
	
	static {
		// TODO
	}
	
	public static KuzhaObject getController(final KuzhaEngine engine) {
		KuzhaObject result = new KzUserObject(KuzhaEngineFactory.getRootObject());
		new KzBuiltinFunction(result, "actor", 1) {
			@Override
			protected KuzhaObject exec(KuzhaObject _this, KuzhaObject[] args) throws Exception {
				KuzhaObject object = cast(KuzhaObject.class, args[0], 0);
				return new KzLocalActor(engine, object);
			}
		}.regist();
		return result;
	}
}
